<script>
import config from "@/config";
import { token } from "@/utils";

export default {
  onLaunch: function () {
    this.disableTabBar();
    this.initConfig();
    this.initSystemInfo();

    // 检查登录状态
    this.checkLogin();
  },
  options: {
    multipleSlots: true,
    virtualHost: true,
  },
  methods: {
    initSystemInfo() {
      const systemInfo = uni.getSystemInfoSync();
      const statusBarHeight = systemInfo.statusBarHeight;
      // 设置全局参数
      this.globalData.systemInfo = { statusBarHeight, navBarHeight: 0 };
      if (systemInfo.uniPlatform !== "web") {
        const { top, height } = uni.getMenuButtonBoundingClientRect();
        const navBarHeight = height + (top - statusBarHeight) * 2;
        this.globalData.systemInfo.navBarHeight = navBarHeight;
      }
    },
    disableTabBar() {
      // 隐藏原生tabBar
      uni.hideTabBar();
    },
    initConfig() {
      this.globalData.config = config;
    },
    checkLogin() {
      if (!token.getToken()) {
        return this.$tab.reLaunch("/pages/login");
      }
      // this.$store.dispatch("GetInfo");
    },
  },
};
</script>
